# Generate 4 unique digit number as answer
# Ask user for input 4 digit number
# Compare Answer with user's number
# Return xAxB to user
import sys
import random

def genAns(dig):
    return random.sample('0123456789', dig)

def compNumber(d1, d2):
    mA = 0
    mB = 0
    global uDig
    for i in range(0,uDig):
        for j in range(0, uDig):
            if i <> j :
                if d1[i] == int(d2[j]): mB += 1
            else:
                if d1[i] == int(d2[j]): mA += 1
    return (mA, mB)
uDig = 0

while uDig<3 or uDig>7:
    try:
        uDig = input('Please fill in digit number you want to guess(from 3 to 7): ')    
    except:
        uDig = 0

Ans = genAns(uDig)
uGuess=''
while (not uGuess.isdigit()) or (len(uGuess) <> uDig):
    uGuess = raw_input('Fill in your number(%d digit): ' % uDig)    

print Ans
print uGuess
print compNumber(Ans, uGuess)
